//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    imgUrl: baseJs.imgUrl,
    pageIndex: 1,
    state: "",
    teacherList: [],
    searchKey: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
    })
    this.GetTeacher();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetTeacher();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  //
  GetTeacher: function() {
    var that = this;
    var pageIndex = this.data.pageIndex;
    var searchKey = this.data.searchKey;
    var teacherList = this.data.teacherList;
    if (pageIndex == 1) {
      wx.showLoading({
        title: '加载中',
      })
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetTeacher&PageSize=10&PageIndex=" + pageIndex + "&SearchKey=" + searchKey),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          teacherList.push(json[i])
        }
        that.setData({
          teacherList: teacherList,
        })
        console.log(teacherList);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
      }
    })
  },
  // 
  searchInput: function(e) {
    var that = this;
    this.setData({
      searchKey: e.detail.value,
    })
  },
  // 
  searchTap: function() {
    var that = this;
    this.data.pageIndex = 1;
    this.data.teacherList = [];
    that.GetTeacher();
  },
  // 
  all: function() {
    var that = this;
    this.data.pageIndex = 1;
    this.data.searchKey = '';
    this.data.teacherList = [];
    that.GetTeacher();
  },
})